#!/bin/bash

# export LC_ALL="zh_CN.UTF-8"
# export LANG="zh_CN.UTF-8"

script_dir()
{
    SOURCE="${BASH_SOURCE[0]}"
    while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
	DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
	SOURCE="$(readlink "$SOURCE")"
	[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
    done
    DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
    echo ${DIR}
}

export PRODUCT_VERSION=1.0.0
export PRODUCT_COMMIT=7db28d6c04b9020bc44de669c8b6950b4a5d7037
export PRODUCT_COMMIT_TIME=20170914084427
export PRODUCT_BUILD_TIME=20170914091221

export PRODUCT_HOME="$( script_dir )"

echo ""
echo "PRODUCT_HOME: $PRODUCT_HOME"
echo "PRODUCT_LOG: $PRODUCT_HOME/logs"
echo "PRODUCT_BUILD_INFO:"
echo "------------------------------------------------------"
echo "| Version: $PRODUCT_VERSION"
echo "| Build Time: $PRODUCT_BUILD_TIME"
echo "| Commit Time: $PRODUCT_COMMIT_TIME"
echo "| Git Commit: $PRODUCT_COMMIT"
echo "------------------------------------------------------"


# PIDFILE=${PRODUCT_HOME}/application.pid
# if [[ ! -f ${PIDFILE} ]]
# then
#    echo "Bot Platform is already stopped."
#    echo ""
#    exit 1
# fi

# kill -s TERM `cat ${PIDFILE}`
# echo "Iot Server is stopped successfully."

   pid="$(ps -ef | grep hna-iot-server.1.0.0.jar | grep -v grep | awk '{print $2}')"
   kill -9 $pid
   echo kill -9 $pid
   echo "Iot Server is stopped successfully."
